package com.megurokai.tool;

import com.megurokai.paint.PaintManager;

import android.view.MotionEvent;
import android.view.ScaleGestureDetector;

public class ToolScroll implements Tool {
	protected PaintManager manager;
	protected float fromScreenX;
	protected float fromScreenY;
	protected float fromOffsetX;
	protected float fromOffsetY;
	protected float moveX;
	protected float moveY;
	protected float rate;
	
	public ToolScroll(PaintManager view){
		this.manager = view;
	}
	
	@Override
	public boolean onToudhDown(MotionEvent event) {
		fromScreenX = event.getX();
		fromScreenY = event.getY();
		fromOffsetX = manager.getOffsetX();
		fromOffsetY = manager.getOffsetY();
		
		return true;
	}

	@Override
	public boolean onTouchUp(MotionEvent event) {
		manager.setLock(false);
		return false;
	}

	@Override
	public boolean onTouchMove(MotionEvent event) {
		manager.setLock(true);
		rate = manager.getZoomRate();
		moveX = (fromScreenX - event.getX()) / rate;
		moveY = (fromScreenY - event.getY()) / rate;
		
		manager.setOffsetX(fromOffsetX+moveX);
		manager.setOffsetY(fromOffsetY+moveY);
		return true;
	}

	@Override
	public boolean onScale(ScaleGestureDetector detector) {
		// 何もしない
		return false;
	}

	@Override
	public boolean onScaleBegin(ScaleGestureDetector detector) {
		// 何もしない
		return false;
	}

	@Override
	public boolean onScaleEnd(ScaleGestureDetector detector) {
		// 何もしない
		return false;
	}

}
